<?php 
	session_start();
	$var1= $_SESSION["registrado"];
	$var2= $_SESSION["administrador"];
	if ($var1 == null): {
		echo ("User not registered");
	} elseif ($var2 == 1): { 
			echo ("User without permissions");
	} else : {

    //veo si tengo que ordenar en ascendente o descendente
    $ascendente=$_GET['asc'];
    if ($ascendente==1) {
        $ascendente=0;
        $aux='desc';
    }
    else {
        $ascendente=1;
        $aux='asc';
    }
    ?>


<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.css" rel="stylesheet"	media="screen">

<title>My project manager</title>



</head>

<body>
	<?php include ('configuration.php'); ?>
	<script type="text/javascript"
		src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/bootstrap.js"></script>


	<div class="navbar navbar-inverse navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container-fluid">
				<button type="button" class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse">
					<span class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="brand" href="http://localhost/bases--grupo10/homeNoAdmin.php?">My project manager</a>
				<div class="nav-collapse collapse">
					<p class="navbar-text pull-right">
					
						<a href="http://localhost/bases--grupo10/logout.php?" class="navbar-link">Log out</a>
					</p>
					<ul class="nav">
						<li class="active"><a href="http://localhost/bases--grupo10/homeNoAdmin.php?">Home</a></li>
						<li><a href="http://localhost/bases--grupo10/about.php?">About</a></li>
						<li><a href="http://localhost/bases--grupo10/contact.php?">Contact</a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>

	<div class="span10">
		<div class="span9">
			<div class="hero-unit">
			<?php
			$var3= $_SESSION["variable"];?>
			<h1>Hello <?php echo $var3?>!</h1>
			<p>No administrator profile</p>
			</div>
		</div>
	</div>
	
	<div class="span12 offset1">	
	<table class="table table-striped">  
        <thead>  
          <tr>  
            <th>Project Name</th>  
            <th><a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/order_projects_NoAdmin.php?opcion=1&&asc=<?php echo $ascendente ?>">Version</a></th>  
            <th><a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/order_projects_NoAdmin.php?opcion=2&&asc=<?php echo $ascendente ?>">Initial date</a></th>  
            <th><a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/order_projects_NoAdmin.php?opcion=3&&asc=<?php echo $ascendente ?>">Final date</a></th> 
            <th><a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/order_projects_NoAdmin.php?opcion=4&&asc=<?php echo $ascendente ?>">Advance</a></th> 
          </tr>  
        </thead>  
        <tbody>       
         <?php
           
        $opcion=$_GET['opcion'];
         
        if ($opcion==1){
    
             $q1 = mysql_query("select p.id_project, p.name_project, p.id_version, p.advantage, p.initial_date, p.final_date
                                from project p where p.id_version=(select max(P2.id_version)
                                      from Project P2
                                      where P.id_project=P2.id_project and P.deleted=0)
                                order by p.id_version $aux") or die ("Query error");
        }
         else if ($opcion==2){
            $q1 = mysql_query("select p.id_project, p.name_project, p.id_version, p.advantage, p.initial_date, p.final_date
                                from project p where p.id_version=(select max(P2.id_version)
                                      from Project P2
                                      where P.id_project=P2.id_project and P.deleted=0)
                                order by p.initial_date $aux") or die ("Query error");
        }else if ($opcion==3){
            $q1 = mysql_query("select p.id_project, p.name_project, p.id_version, p.advantage, p.initial_date, p.final_date
                                from project p where p.id_version=(select max(P2.id_version)
                                      from Project P2
                                      where P.id_project=P2.id_project and P.deleted=0)
                                order by p.final_date $aux ") or die ("Query error");
        }else {
            $q1 = mysql_query("select p.id_project, p.name_project, p.id_version, p.advantage, p.initial_date, p.final_date
                                from project p where p.id_version=(select max(P2.id_version)
                                      from Project P2
                                      where P.id_project=P2.id_project and P.deleted=0)
                                order by p.advantage $aux") or die ("Query error");
        }
         while($row=mysql_fetch_array($q1)){
            echo "<tr>";
            echo "<td>" . $row["name_project"] . "</td>";
            echo "<td>" . $row["id_version"] . "</td>";
            echo "<td>" . $row["initial_date"] . "</td>";
            echo "<td>" . $row["final_date"] . "</td>";
            echo "<td>" . $row["advantage"] . "</td>";
            echo "</tr>";
         }         
         ?>
        </tbody>  
      </table>
    </div>       
</body>  
</html>  


<?php }endif;?>